package com.zeroup.auto.window;

import android.content.Context;
import android.graphics.PixelFormat;
import android.os.Build;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;

import com.blankj.utilcode.util.ScreenUtils;
import com.zeroup.auto.R;
import com.zeroup.auto.assists.step.WxStep;
import com.ven.assists.stepper.StepManager;

import org.kymjs.kjframe.ui.BindView;


public class FloatingWindowManager {
    private WindowManager windowManager;
    private View floatingView;
    private WindowManager.LayoutParams params;

    @BindView(id= R.id.btn_open_social)
    Button btn_open_social;

    public FloatingWindowManager(Context context) {
        windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        floatingView = LayoutInflater.from(context).inflate(R.layout.view_main_over, null);
//        FinalActivity.initInjectedView(this,floatingView);
        if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.O){
            params = new WindowManager.LayoutParams(
                    WindowManager.LayoutParams.WRAP_CONTENT,
                    WindowManager.LayoutParams.WRAP_CONTENT,
                    WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
                    WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                    PixelFormat.TRANSLUCENT);
        }else{
            params = new WindowManager.LayoutParams(
                    WindowManager.LayoutParams.WRAP_CONTENT,
                    WindowManager.LayoutParams.WRAP_CONTENT,
                    WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
                    WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                    PixelFormat.TRANSLUCENT);
        }


        params.gravity = Gravity.START | Gravity.TOP;
        params.x = 0;
        params.y = 0;
    }


    public void showFloatingWindow() {
        windowManager.addView(floatingView, params);
    }

    public void dismissFloatingWindow() {
        if (floatingView != null) {
            windowManager.removeView(floatingView);
        }
    }


    public void btn_open_social(View view){
        StepManager.INSTANCE.execute(WxStep.class,1,0,null,true);
    }

}
